import libs from '../assets/js/libs';
import { shareActive } from '../assets/js/hscfApi';

export default {
  methods: {
    getUserInfo() {
      return libs.axios.post('/nyUser').then(({data}) => {
        if (data.header.ret === 'S') {
          const userInfo = data.data;
          localStorage.setItem('userInfo', JSON.stringify(userInfo));
          return userInfo;
        } else {
          throw new Error(data.header.msg[0]);
        }
      });
    },
    shareActive() {
      libs.catchErr(this.getUserInfo().then(data => {
        let url = `${location.protocol}//${location.host}`;
        url = process.env.NODE_ENV !== 'development' ? url + '/invite' : url + '/#/invite';
        url += `?invite-code=${data.inviteCode}`;
        shareActive({
          isRefresh: false,
          url,
          title: '惠商车服新春送福，福进万家！',
          content: '惠商车服春节送福利，集福卡闹新春，百万福利等着你！',
          img: process.env.NODE_ENV !== 'production' ? 'img/share/fu.png' : 'res/img/share/fu.png'
        });
      }))
    }
  }
}
